package cn.thornbird.orgsync.controller;

import cn.thornbird.orgsync.annotation.CurrentUser;
import cn.thornbird.orgsync.model.Result;
import cn.thornbird.orgsync.model.statistic.StatisticData;
import cn.thornbird.orgsync.model.UserData;
import cn.thornbird.orgsync.model.statistic.TaskStatisticData;
import cn.thornbird.orgsync.service.StatisticService;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Date;

@RestController
@RequestMapping(value = "/api/statistic")
@Api
@AllArgsConstructor
public class StatisticController {

    private StatisticService statisticService;

    @GetMapping("counts")
    public Result<StatisticData> getStatisticData(@CurrentUser @ApiIgnore UserData userData) {
        return Result.success(statisticService.getStatisticData(userData));
    }

    @GetMapping("taskCounts")
    public Result<TaskStatisticData> getTaskStatisticData(@CurrentUser @ApiIgnore UserData userData,
                                                                @DateTimeFormat(pattern="yyyy-MM-dd") Date startDate,
                                                                @DateTimeFormat(pattern="yyyy-MM-dd") Date endDate) {
        return Result.success(statisticService.getTaskStatisticData(userData, startDate, endDate));
    }

}
